#!/bin/bash

export ANDROID_NDK=~/Android/android-ndk-r13b


currentPath=`pwd`
destDir="编译好的libs"
rm -rf $currentPath/$destDir
mkdir $currentPath/$destDir

for i in android android-armeabi android64-aarch64 android-x86 android64
do
	rm -rf $currentPath/{arm64-v8a, armeabi, armeabi-v7a, x86_64, x86}-toolchain
	rm -rf $currentPath/libs
	cd $currentPath


	echo "开始编译" 
	echo $i
	if [ "$i" = "android64-aarch64" ]; then
        ANDROID_API=21 bash ./build-openssl4android.sh $i > /dev/null 2&>1
    elif [ "$i" = "x86_64" ]; then
	   ANDROID_API=21 bash ./build-openssl4android.sh $i > /dev/null 2&>1
    else
	   ANDROID_API=9 bash ./build-openssl4android.sh $i > /dev/null 2&>1
    fi
	unset ANDROID_API

	for j in libssl libcrypto
	do
		echo $currentPath/openssl-1.1.0f/$j.so
		echo `find $currentPath/libs/ -name $j.a`

		
		mv $currentPath/openssl-1.1.0f/$j.so `find $currentPath/libs/ -name $j.a|xargs dirname`/
	done	
	cd $currentPath/$destDir && cp -r $currentPath/libs/* .
	echo $i
	echo "编译完成"
done
